<template>
  <div class="Login-container">
    <!-- 登录头部 -->
    <div class="Login-header">
      <div>
      </div>
      <div style="letter-spacing:5px;font-weight:bold;text-indent: 40px">{{msg[0]}}</div>
      <!-- 循环头部的圆圈 -->
      <div>
        <ul v-for="item in list" :key="item.id">
          <li>{{ item }}</li>
        </ul>
      </div>
    </div>
    <!-- 登录模块 -->
    <div class="tels">
      <el-form name="form" :rules="rules" :model="ruleForm" status-icon  ref="ruleForm" label-width="0px" class="demo-ruleForm">
        <!-- 用户名 -->
        <el-form-item prop="username">
          <el-input type="text" id="username" name="username" v-model="ruleForm.username" autocomplete="off" clearable placeholder="请输入您的用户名" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input type="password" name="password" id="password" v-model="ruleForm.password" autocomplete="off" show-password clearable placeholder="请输入您的密码" prefix-icon='el-icon-lock'></el-input>
        </el-form-item>
          <!-- 登录按钮 -->
          <el-button class="Login-btn"  id="btn" @click="submitForm('form')">{{msg[3]}}</el-button>
          <!-- 复选框 -->
          <el-checkbox class="jzmm" v-model="isRememberpass">{{msg[4]}}</el-checkbox>
          <el-checkbox class="jzmm" v-model="isRememberyhm">{{msg[5]}}</el-checkbox>
      </el-form>
    </div>
    <!-- 找回密码，快速注册 -->
    <div class="zhmmkszc">
        <div class="zhmmkszc-left">
          <router-link to="">
            <img class="ZHMM" :src="puctuer.zhmmm" alt="">
            <span>{{msg[6]}}</span>
          </router-link>
        </div>
        <div class="zhmmkszc-right">
            <router-link to="/Register">
              <img class="KSDL" :src="puctuer.kszc" alt="">
              <span>{{msg[7]}}</span>
            </router-link>
        </div>
    </div>
       <!-- 其他登录方式 -->
    <div class="qtdlfs">
        <div></div>
        <div>{{msg[8]}}</div>
        <div></div>
    </div>
    <!-- qq,微信 -->
    <div class="qqwx">
      <!-- qq -->
        <div @click="QQ" style="cursor: pointer;">
            <img :src="puctuer.QQ" alt="">
            <span>{{msg[9]}}</span>
           <div v-show="qqshow"> <img style="width:60px;height:60px;" :src="puctuer.ewm" alt=""></div>
        </div>
        <!-- 微信 -->
        <div @click="vx" style="cursor: pointer;">
            <img :src="puctuer.wx" alt="">
            <span>{{msg[10]}}</span>
            <div v-show="vxshow"> <img style="width:65px;height:65px;" :src="puctuer.ewm" alt=""></div>
        </div>
    </div>
</div>
</template>
<script>
import axios from "@/api/request";
import jsCookie from 'js-cookie';
import { mapMutations,mapState } from "vuex";

export default {
  name: "Login",

  data() {
    return {
      ruleForm: { 
        password: '', 
        username: '',
    },
    rules: {
        username: [
          {required: true, message: "用户名不能为空", trigger: 'blur'},
          {min: 5, max: 12, message: "用户名5-12位", trigger: 'blur'}
        ],
        password: [
          {required: true, message: "密码不能为空", trigger: 'blur'},
          {min: 6, max: 30, message: "密码6-30位", trigger: 'blur'}
        ],
      } ,
        isRememberpass: false,
        isRememberyhm:false,
        content: '',
        psd: '',
        yzm: '',
        qqshow:false,
        vxshow:false,
        msg:['京东登录','521luo','看不清？请点击','登录','记住密码','记住用户名','找回密码','快速注册','其他登录方式','QQ','微信'],
        puctuer:{
            zjt:require('@/assets/images/左箭头.png'),
            zhmmm:require('@/assets/images/找回密码.png'),
            kszc:require('@/assets/images/快速注册.png'),
            QQ:require('@/assets/images/qqqqqq (1).png'),
            wx:require('@/assets/images/vx.png'),
            ewm:require('@/assets/images/二维码.png'),
        },
        list:['','',''],
        // userToken:'', // 用于存储从后台获取的token
    };
         },
       
      methods: {
      // 验证登录（跟数据库里面的用户名密码做对比）
      submitForm(){
      // 执行校验
      this.$refs.ruleForm.validate(valid => {
        // 验证通过为true，有一个不通过就是false
        if (valid) {
            // 通过校验
            // 登录处理

            // 匹配登录用户名
            jsCookie.set('username',this.ruleForm.username)
            
            // 获取sql里面的数据
            axios({
                method: 'post',
                url: 'http://127.0.0.1:3000/admin/login',
                data: {
                    username:this.ruleForm.username,
                    password:this.ruleForm.password,
                }
              })
                .then(res => {
                 if (res.data.status==200) {
                        alert('登录成功')
                        //  console.log(res);
                         window.sessionStorage.setItem("token",res.data.token)
                        //  console.log(sessionStorage.getItem('token'));
                        this.$router.replace('/myjd')
                      
                        this.USER_LOGIN(res.data);
                    }else{
                        alert('用户名或者密码不正确，登录失败')
                        location.reload()
                    }
                })
                .catch(err => {
                    console.error("登录失败"+err);
                })
        } else {
          // 没通过校验
          this.$message.error('请输入正确格式的用户名或者密码');
                return false;
        }
      })
        },
        // 点击qq.弹出二维码
        QQ(){
          this.qqshow = !this.qqshow
        },
        // 点击vx，弹出二维码
        vx(){
          this.vxshow = !this.vxshow
        },

        ...mapMutations(['USER_LOGIN']),
        ...mapState({
			loginStatus:state=>state.user.loginStatus,
			userInfo:state=>state.user.userInfo,
		})
      }
    
};
</script> 

<style scoped>
.Login-container {
  background-color: rgb(243, 245, 247);
  height:700px;
  width: 400px;
  margin: 0 auto;
  user-select: none;
}
.Login-header {
  width: 100%;
  height: 44px;
  background: linear-gradient(white, rgb(239, 239, 239));
  border-bottom: 2px solid lightgray;
  display: flex;
}
.Login-header > div:nth-of-type(1) {
  width: 15%;
  height: 100%;
}
.Login-header > div:nth-of-type(2) {
  width: 65%;
  height: 100%;
  text-align: center;
  line-height: 44px;
}
.Login-header > div:nth-of-type(3) {
  width: 20%;
  height: 100%;
  margin-left: 40px
}
.zjt {
  width: 25px;
  height: 25px;
  margin-top: 9.5px;
  margin-left: 5px;
}
.Login-header ul li {
  float: left;
  list-style: none;
  width: 4px;
  height: 4px;
  margin-left: 3px;
  border: 2px solid black;
  border-radius: 50%;
  margin-top: 5px;
}
.el-input{
    width: 350px;

    margin-top: 15px;
    outline: none;
    border-radius: 6px;
}
.tels{
  width: 350px;
  margin-left: 25px;
  margin-top: 15px;
  outline: none;
  border-radius: 6px;
}
.YZM{
    width: 175px;
}
.yanzheng{
    border: 1px solid  rgb(228, 228, 228);
    background: #008c8c;
    display: inline-block;
    height: 30px;
    width: 60px;
    text-align: center;
    line-height: 30px;
    margin-left: 125px;
}
.butn{
    width: 105px;
    height: 30px;
    margin-left: 5px;
    font-size: 12px;
    border: 1px solid rgb(228, 228, 228);
}
.Login-btn{
    width: 350px;
    margin-top: 20px;
    height: 40px;
    border: 1px solid rgb(228, 228, 228);
    border-radius: 6px;
    letter-spacing: 10px;
}
.jzmm{
    margin-top: 20px;
}
.zhmmkszc{
    display: flex;
    width: 400px;
}
.zhmmkszc-left,.zhmmkszc-right{
    width: 50%;
    height: 50px;
    margin-top: 40px;
    text-align: center;
    line-height: 50px;
}
.zhmmkszc-left>img,.zhmmkszc-right>img{
    width: 28px;
    vertical-align: middle;
    height: 26px; 
    margin-right: 5px;
}
.KSDL,.ZHMM{
    width: 28px;
    vertical-align: middle;
    height: 26px; 
    margin-right: 5px;
}
.qtdlfs{
    display: flex;
    height: 80px;
    width: 350px;
    margin-left: 25px;
}
.qtdlfs>div:nth-of-type(1){
    width: 35%;
    border: 0.5px solid gray;
    margin-top: 39.5px;
    height: 0;
}
.qtdlfs>div:nth-of-type(2){
    width: 30%;
    text-align: center;
    line-height: 80px;
}
.qtdlfs>div:nth-of-type(3){
    width: 35%;
    border: 0.5px solid gray;
    margin-top: 39.5px;
    height: 0;
}
.qqwx{
    display: flex;
}
.qqwx>div{
    margin-left: 85px;
}
.qqwx>div>img{
    vertical-align: middle;
}
.qqwx>div>span{
    display: inline-block;
    margin-left: 5px;
    line-height: 50px;
}
a{
  text-decoration: none;
  color: black;
}
</style> -->
